<template>
    <div class="global">
        <div class="divItem">
            发现多个同位置测点链接方案，请确认
        </div>
        <hr>
        <div ref="list" class="divItem">
            <div v-for="(item, index) in pos">
                <input :id="get_ref(index)" :ref="get_ref(index)" type="checkbox" :value="item" :name="get_ref(index)">
                <span style="color: red">{{ item }}</span> |
                点名：<span style="color:red">{{ get_test_point_name(item) }}</span> | 值：<span
                    style="color:blue">{{ get_test_point_value(item) }}</span>
            </div>
        </div>
        <hr>
        <!--        <p>{{ para }}</p>-->
        <button style="margin:3px;" @click="onclick('确定')">确定</button>
    </div>
</template>

<script>
import tpi from './js/testpointinfo.js'
import SystemDemo from "@/components/js/systemdemo";
import Systemdemo from "@/components/js/systemdemo";

export default {
    name: "TestPointInfo",
    data() {
        return {
            pos: JSON.parse(this.$route.params.info), //set.get_device(),
            // numOfPos: this.pos.length,
        }
    },
    methods: {
        onclick(id) {
            // 获取选中的pos
            // wps.ShowDialog("/", `this.pos = ${document.getElementById("ref0").checked}`)
            // wps.ShowDialog("/", `this.$refs.list = ${this.$refs.ref0.checked}`)  # vue写法无法获取checkbox的值
            let checked_pos = []
            for (let [i, pos] of this.pos.entries()) {
                let ele = document.getElementById(this.get_ref(i))
                if (ele.checked) {
                    checked_pos.push(pos)
                }
            }
            if (checked_pos.length === 1) {
                SystemDemo.fill_cell(null, null, "formula", `=${checked_pos[0]}`)
            } else if (checked_pos.length === 0) {
                wps.ShowDialog("/", "未选中测点")
                return
            } else {
                SystemDemo.fill_cell(null, null, "formula", `=AVERAGE(${checked_pos.join(",")})`)
            }
            // tpi.onclick(id);

            // this.$forceUpdate();  // 界面不更新，需要显示调用或鼠标移动到表格区域才会更新
            // let tsId = wps.PluginStorage.getItem("testPointInfo"); // 通过面板名获取面板的id
            // let taskPane = wps.GetTaskPane(tsId);
            // taskPane.Visible = false;
            SystemDemo.showTaskPane("testPointInfo/", "链接测点", false)
        },
        get_test_point_name(item) {
            return SystemDemo.get_test_point_name(item)
        },
        get_test_point_value(item) {
            return SystemDemo.get_cell_value_by_pos(item)
        },
        get_ref(index) {
            return `ref${index}`;
        },
    },
}
</script>

<style scoped>

</style>